/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.database;

import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;

public class PictureCursor extends SQLiteCursor {
	
	private static final String[] mColumns = { DBAdapter.DB_Picture_ImageText, DBAdapter.DB_Picture_ImagePath, DBAdapter.DB_Picture_ImageSound };
	
	public static PictureCursor query(SQLiteDatabase mDb, int id) {
		final String select  = DBAdapter.DB_Picture_ID + " = " + id;
		return (PictureCursor) mDb.queryWithFactory(new Factory<PictureCursor>(PictureCursor.class), true, DBAdapter.DB_Picture, mColumns, select, null, null, null, null, null);
	}

	private int mImagePathIndex;
	private int mImageTextIndex;
	private int mSoundPathIndex;
	
	public PictureCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
		
		mImagePathIndex = getColumnIndexOrThrow(DBAdapter.DB_Picture_ImagePath);
		mImageTextIndex = getColumnIndexOrThrow(DBAdapter.DB_Picture_ImageText);
		mSoundPathIndex = getColumnIndexOrThrow(DBAdapter.DB_Picture_ImageSound);
	}
	
	/**
	 * Get the path from a cursor.
	 * 
	 * This is used in combination with fetchPicture(). This extracts the path from the cursor, that is the location of the picture file.
	 * 
	 * @return  A string containing the image path.
	 */
	public String getPicturePath() {
		return getString(mImagePathIndex);
	}
	
	/**
	 * Get the text from a cursor.
	 * 
	 * This is used in combination with fetchPicture(). This extracts the text from the cursor, that is the text to be put with the picture.
	 * 
	 * @return A string containing the text.
	 */
	public String getPictureText() {
		return getString(mImageTextIndex);
	}
	
	/**
	 * Get the sound path from a cursor.
	 * 
	 * This is used in combination with fetchPicture(). This extracts the sound path from the cursor, that is the location of the sound file associated with a picture.
	 * 
	 * @return  A string containing the sound path.
	 */
	public String getSoundPath() {
		return getString(mSoundPathIndex);
	}

}
